package net.maku.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.convert.PreOrderConvert;
import net.maku.entity.PreOrderEntity;
import net.maku.query.PreOrderQuery;
import net.maku.vo.PreOrderVO;
import net.maku.dao.PreOrderDao;
import net.maku.service.PreOrderService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 预购管理
 *
 * @author 小车 
 * @since 1.0.0 2025-03-25
 */
@Service
@AllArgsConstructor
public class PreOrderServiceImpl extends BaseServiceImpl<PreOrderDao, PreOrderEntity> implements PreOrderService {

    @Override
    public PageResult<PreOrderVO> page(PreOrderQuery query) {
        IPage<PreOrderEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(PreOrderConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<PreOrderEntity> getWrapper(PreOrderQuery query){
        LambdaQueryWrapper<PreOrderEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(PreOrderVO vo) {
        PreOrderEntity entity = PreOrderConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(PreOrderVO vo) {
        PreOrderEntity entity = PreOrderConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}